package com.study.hot.architecture.mvx.mvp.presenter;


import com.study.hot.architecture.mvx.mvp.model.Board;
import com.study.hot.architecture.mvx.mvp.model.Player;
import com.study.hot.architecture.mvx.mvp.view.JZQView;

/**
 * <pre>
 *     author : slx
 *     time   : 2020/11/20
 *     desc   : MVP p层,主要处理逻辑
 *              view层关注用户交互，present关注交互的逻辑处理
 * </pre>
 */
public class JZQPresenter {
    private Board model;
    private JZQView view;

    public JZQPresenter(JZQView view) {
        this.view = view;
        this.model = new Board();
    }

    // 按钮点下逻辑处理
    public void onButtonSelected(int row, int col) {
        Player playerThatMoved = model.mark(row, col);
        if (playerThatMoved != null) {
            view.setButtonText(row, col, playerThatMoved.toString());
            if (model.getWinner() != null) {
                view.showWinner(String.format("%s 获胜", playerThatMoved.toString()));
            }
        }
    }

    public void onRestartGame(){
        view.clearButtonText();
        view.clearWinnerDisplay();
        model.restart();
    }

}
